from django.contrib import admin
from .models import LifestyleType,LifestyleTag,Lifestyle,Editor_Recommend
# Register your models here.
@admin.register(LifestyleType)
class LifestyleTypeAdmin(admin.ModelAdmin):
    list_display = ('id','wz_class')
    def desc_short(self, obj):
        return obj.desc[:50] + '...' if len(obj.desc) > 50 else obj.desc
    desc_short.short_description = '摘要'
    def author(self, obj):
        return obj.user.username if obj.user else '无作者'
    author.short_description = '作者'
    def status_label(self, obj):
        return obj.get_status_display()
    status_label.short_description = '状态'
    def created_at(self, obj):
        return obj.create_time.strftime("%Y-%m-%d %H:%M")
    created_at.short_description = '创建时间'

@admin.register(LifestyleTag)
class LifestyleTagAdmin(admin.ModelAdmin):
    list_display = ('id','tag_name')

@admin.register(Lifestyle)
class LifestyleAdmin(admin.ModelAdmin):
    list_display = ('id', 'title', 'author', 'status_label', 'created_at')
    search_fields = ('title', 'desc', 'user__username')
    list_filter = ('status', 'category', 'create_time')

    def author(self, obj):
        return obj.user.name if obj.user else '无作者'
    author.short_description = '作者'

    def status_label(self, obj):
        return obj.get_status_display()
    status_label.short_description = '状态'

    def created_at(self, obj):
        return obj.create_time.strftime("%Y-%m-%d %H:%M")
    created_at.short_description = '创建时间'


@admin.register(Editor_Recommend)
class Editor_RecommendAdmin(admin.ModelAdmin):
    list_display = ('id', 'blog', 'is_rec', 'created_at')
    list_filter = ('is_rec', 'create_time')
    def created_at(self, obj):
        return obj.create_time.strftime("%Y-%m-%d %H:%M")
    created_at.short_description = '创建时间'




